package ide.ccf.ccproject.pages;

import ide.ccf.ccproject.editors.ProjectFileEditor;
import ide.ccf.ccproject.editors.ProjectFileViewerConfiguration;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.IFormPage;

/**
 * CCF项目文件源码页面
 *
 */
public class ProjectFileSourcePage extends TextEditor implements IFormPage
{
	private FormEditor formEditor;
	private int pindex;
	private boolean pactive;
	
	/**
	 * 构造器
	 * @param editor
	 */
	public ProjectFileSourcePage(ProjectFileEditor editor)
	{
		super();

		formEditor = editor;
		setSourceViewerConfiguration(new ProjectFileViewerConfiguration(editor.getColorManager()));
	}
	
	/**
	 * 是否允许离开页面
	 */
	public boolean canLeaveThePage() 
	{
		return true;
	}
	
	/**
	 * 是否可编辑
	 */
	public boolean isEditable() 
	{
		return false;
	}

	/**
	 * 文档
	 * @return
	 */
	public IDocument getDocument()
	{
		return getSourceViewer().getDocument();		
	}
	
	/**
	 * 编辑器实例
	 */
    public FormEditor getEditor() 
    {
    	return formEditor;
    }
    
    /**
     * 编辑器ID
     */
    public String getId() 
    {
    	return "ide.ccf.ccproject.pages.ProjectFileSourcePage";
    }
    
    /**
     * 页面序号
     */
    public int getIndex() 
    {
    	return pindex;
    }
    
    /**
     * IManagedForm
     */
    public IManagedForm getManagedForm() 
    {
    	return null;
    }
    
    /**
     * 页面显示
     */
    public Control getPartControl() 
    {
    	
    	if (getSourceViewer() != null) 
    	{
    		//IDocumentPartitioner partitioner = new FastPartitioner(ProjectPlugin.getDefault().getProjectFilePartitionScanner(), ProjectFilePartitionScanner.PARTITION_TYPES);

    		//partitioner.connect(getSourceViewer().getDocument());
    		//getSourceViewer().getDocument().setDocumentPartitioner(partitioner);    		
    	}
    	return getSourceViewer().getTextWidget();
    }
    
    /**
     * 初始化
     */
    public void initialize(FormEditor editor) 
    {
    	formEditor = editor;
    }
    
    /**
     * 是否激活
     */
	public boolean isActive() 
	{
		return pactive;
	}
	
	/**
	 * 是否编辑器
	 */
    public boolean isEditor() 
    {
    	return true;    	
    }
    
    /**
     * 提示
     */
    public boolean selectReveal(Object object) 
    {
    	return false;
    }
    
    /**
     * 激活
     */
    public void setActive(boolean active) 
    {
    	pactive = active;
    }
    
    /**
     * 设置序号
     */
    public void setIndex(int index) 
    {
    	pindex = index;
    }	
}